<template>
  <div>
    <div>
      <Form
        ref="formValidate"
        :model="formValidate"
        :label-width="80"
      >
        <Row justify="space-between">
          <Col span="6">
            <FormItem label="仓库编号" prop="sid">
              <Select v-model="formValidate.sid" clearable filterable placeholder="选择仓库编号">
                <Option 
                v-for="(item,index) in stores.sids"
                :value="item.value"
                :key="index"
                >{{item.label}}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="仓库名称" prop="sname">
              <Select v-model="formValidate.sname" clearable placeholder="选择仓库名称" filterable>
                <Option 
                v-for="(item,index) in stores.snames"
                :value="item.value"
                :key="index"
                >{{item.label}}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="作物编号" prop="cid">
              <Select v-model="formValidate.cid" clearable placeholder="选择作物编号" filterable>
                <Option 
                v-for="(item,index) in crops.cids"
                :value="item.value"
                :key="index"
                >{{item.label}}</Option>
              </Select>
            </FormItem>
          </Col>
        </Row>
        <Row justify="space-between">
          <Col span="6">
            <FormItem label="作物名称" prop="name">
              <Select v-model="formValidate.name" clearable placeholder="选择作物名称" filterable>
                <Option 
                v-for="(item,index) in crops.names"
                :value="item.value"
                :key="index"
                >{{item.label}}</Option>
              </Select>
            </FormItem>
          </Col>
           <Col span="6">
            <FormItem label="批次" prop="batch">
              <Select v-model="formValidate.batch" clearable placeholder="选择批次" filterable>
                <Option 
                v-for="(item,index) in batchs"
                :value="item.value"
                :key="index"
                >{{item.label}}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="入库时间" prop="intime">
              <DatePicker type="date" placeholder="Select date" v-model="formValidate.intime"></DatePicker>
            </FormItem>
          </Col>
        </Row>
        <FormItem>
          <Button type="primary" @click="handleSubmit('formValidate')"
            >搜索</Button
          >
          <Button @click="handleReset('formValidate')" style="margin-left: 8px"
            >重置</Button
          >
        </FormItem>
      </Form>
    </div>
  </div>
</template>
<script>
export default {
  props:{
    stores:Object,
    crops:Object,
    batchs:Array
  },
  data() {
    return {
      formValidate: {
        sid: "",
        sname:"",
        cid:"",
        name:"",
        batch:"",
        intime:""
      },
    };
  },
  
  mounted(){

  },
  methods: {
    handleSubmit() {
      if(this.formValidate){
          this.$emit("search",this.formValidate)
      }
      else{
          this.$Message.info("至少输入一个查询条件")
      }
    },
    handleReset(name) {
      this.$refs[name].resetFields();
    },
  },
};
</script>
